﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using Utils.DC.Web.UI;

public partial class Admin_Pages_AdminAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login"] != null)
        {
            
        }
        else
        {
            Response.Redirect("../Login.aspx");
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        AdminUI adminUI = new AdminUI();
        DataTable ds = adminUI.GetAll().Tables[0];
        DataRow drUser = null;
        DataRow drEmail = null;
        try
        {
            drUser = ds.Select("Username='" + txtUsername.Text + "'")[0];
            if (drUser != null)
            {
                lblUser.Visible = true;
            }
            
        }
        catch (Exception ex)
        {
            try
            {
                lblUser.Visible = false;
                drEmail = ds.Select("Email='" + txtEmail.Text + "'")[0];
                if (drEmail != null)
                {
                    lblEmail.Visible = true;
                }
            }
            catch (Exception ex1)
            {
                lblEmail.Visible = false;
                int result = adminUI.Add(txtUsername.Text.Trim(),Security.Encrypt(txtRePass.Text.Trim()),txtFullName.Text.Trim(),txtPhone.Text.Trim(),txtAddress.Text.Trim(),txtEmail.Text.Trim(),txtDate.SelectedDate,1);
                if (result > 0)
                {
                    Response.Write("<script>alert('Insert successful'); window.location='../Pages/AdminList.aspx';</script>");
                }
                else
                {
                    Response.Write("<script>alert('Insert Fails');</script>");
                }
            }
        }


    }
}
